package com.winsoar.cams.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.winsoar.cams.entity.Kaoqin;
import com.winsoar.cams.service.KaoqinService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Kaoqin)表控制层
 *
 * @author makejava
 * @since 2021-03-20 03:17:05
 */
@Controller
@RequestMapping("kaoqin")
public class KaoqinController {
    /**
     * 服务对象
     */
    @Resource
    private KaoqinService kaoqinService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ResponseBody
    public Kaoqin selectOne(Long id) {
        return this.kaoqinService.queryById(id);
    }

    @PostMapping("/add")
    @ResponseBody
    public Kaoqin add(Kaoqin kaoqin){
        Kaoqin insert = kaoqinService.insert(kaoqin);
        return insert;
    }
    /*跳转考勤记录管理页*/
    @RequestMapping("/tokqList")
    public String tokqList() {
        return "h-ui/kaoqin/index";
    }

    /*获取考勤记录*/
    @RequestMapping("/getInfo")
    @ResponseBody
    public JSONArray getInfo() {
        List<Map<String, Object>> cardInfo = kaoqinService.getInfo();
        JSONArray jsonObject = (JSONArray) JSON.toJSON(cardInfo);
        return jsonObject;
    }

}
